package com.system.zuul.filter;

import com.netflix.zuul.ZuulFilter;
import com.netflix.zuul.context.RequestContext;
import com.netflix.zuul.exception.ZuulException;
import org.springframework.cloud.netflix.zuul.filters.support.FilterConstants;
import org.springframework.stereotype.Component;

/**
 * @author lisiyu
 * @create 2022-10-21 21:24
 * @version1.0
 */
@Component
public class MyRoutingFilter extends ZuulFilter {
    @Override
    public String filterType() {
        return FilterConstants.ROUTE_TYPE;
    }

    @Override
    public int filterOrder() {
        return -1;
    }

    @Override
    public boolean shouldFilter() {
        RequestContext currentContext = RequestContext.getCurrentContext();
        //获取到前面的过滤器传递的值
        boolean sendZuulResponse = currentContext.sendZuulResponse();
        return sendZuulResponse;
    }

    @Override
    public Object run() throws ZuulException {
        System.out.println("routing的run方法执行了");
        return null;
    }
}
